<?php

namespace App\Console\Commands;

use App\Jobs\LandownersOrderConfirmJob;
use Carbon\Carbon;
use Illuminate\Console\Command;

/**
 *
 * 自动确认发货后7天内未确认收货的做地主订单
 *
 * @author maqu
 *
 */
class LandownersOrderConfirmCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'xdd:landownersorderconfirm';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'landowners order confirm orders.';

    /**
     * Create a new queue listen command.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.

     * @return void
     */
    public function fire()
    {

        $now = Carbon::now(config('maqu.TIME_ZONE'));
        $this->info($this->name . ' starting '.$now->toDateTimeString());

        try{
            $this->excute($now);
        } catch(\Exception $e){
            $this->error($e->getMessage());
            $this->error($e->getTraceAsString());
        }

        $endtime =time();

        $this->info($this->name . ' finished. ' . date('Y-m-d H:i:s',$endtime));

        unset($now,$endtime);
    }

    private function excute($now){
        //注意：
        // 这里减去date('Z')是为了获取格林尼治时间，因为数据库里存的日期基本是格林尼治时间
        dispatch(new LandownersOrderConfirmJob($now->timestamp-date('Z')));
    }

}
